home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tpkbd10.zip / KEYTEST.PAS < prev   
Pascal/Delphi Source File  |  1991-07-08  |  4KB  |  104 lines

  1. program keytest;
  2.  
  3. (*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*)
  4. (*                                                                         *)
  5. (*  This is a short program to test and demonstrate some of the most       *)
  6. (*  useful features of the Keyboard unit.  Individual sections are         *)
  7. (*  explained in comments as we go.                                        *)
  8. (*                                                                         *)
  9. (*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*)
  10.  
  11. uses keyboard,dos;
  12.  
  13. const
  14.  intmin=-1000;
  15.  intmax=1000;
  16.  wordmin=0;
  17.  wordmax=1000;
  18.  realmin=-1000.0;
  19.  realmax=1000.0;
  20.  decimals=5;
  21.  stringmax=255;
  22.  
  23. var
  24.  s:string[stringmax];
  25.  regs:registers;
  26.  x,y:byte;
  27.  i:integer;
  28.  w:word;
  29.  r:real;
  30.  numstate:boolean;
  31.  
  32. begin
  33.  s:='Default string';
  34.  chgcursor($20,0); { Shut off cursor }
  35.  writeln('Displaying key states.  Press any key to continue.');
  36.  repeat { Display the states of the various key flags }
  37.   write('States: ');
  38.   if leftshiftdown then write('LSHIFT ') else write('       ');
  39.   if rightshiftdown then write('RSHIFT ') else write('       ');
  40.   if controldown then write('CTRL ') else write('     ');
  41.   if altdown then write('ALT ') else write('    ');
  42.   if getcapslock then write('CAPS ') else write('     ');
  43.   if getnumlock then write('NUM ') else write('    ');
  44.   if getscrolllock then write('SCROLL ') else write('       ');
  45.   if getinsert then write('INSERT ') else write('       ');
  46.   write(^M); { Move to column 1 of current line }
  47.  until keypressed;
  48.  chgcursor(6,7); { Return thin cursor }
  49.  writeln;
  50.  writeln('Key pressed.');
  51.  flushbuffer; { Get rid of the keypress that was created in the buffer }
  52.  write('Enter an integer between ',intmin,' and ',intmax,': ');
  53.  i:=0;
  54.  readint(i,intmin,intmax);
  55.  writeln; { Remember, there is no newline after the input is read }
  56.  writeln('Number returned was ',i);
  57.  write('Enter an unsigned integer between ',wordmin,' and ',wordmax,': ');
  58.  w:=0;
  59.  readno(w,wordmin,wordmax);
  60.  writeln; { Same as above }
  61.  writeln('Number returned was ',w);
  62.  write('Enter a real number between ',realmin:1:decimals,' and ',
  63.   realmax:1:decimals,': ');
  64.  r:=0;
  65.  readreal(r,realmin,realmax,decimals);
  66.  writeln; { Ditto }
  67.  writeln('Number returned was ',r:1:decimals);
  68.  write('Enter a string: ');
  69.  readstr(s,stringmax,[]);
  70.  writeln; { Ditto }
  71.  writeln('String returned was: "',s,'"');
  72.  write('Edit the string: ');
  73.  editstr(s,stringmax,[]);
  74.  writeln; { Ditto }
  75.  writeln('String returned was: "',s,'"');
  76.  nonnumeric:=true;
  77.  numstate:=getnumlock;
  78.  write('Setting NUMLOCK to ON.  Press an arrow key or other keypad key.');
  79.  setnumlock(on);
  80.  repeat until keypressed;
  81.  writeln;
  82.  case getkey of
  83.   home:          writeln('HOME key pressed.');
  84.   uparrow:       writeln('UP ARROW key pressed.');
  85.   pgup:          writeln('PAGE UP key pressed.');
  86.   leftarrow:     writeln('LEFT ARROW key pressed.');
  87.   rightarrow:    writeln('RIGHT ARROW key pressed.');
  88.   end_:          writeln('END key pressed.');
  89.   downarrow:     writeln('DOWN ARROW key pressed.');
  90.   pgdn:          writeln('PAGE DOWN key pressed.');
  91.   ins:           writeln('INSERT key pressed.');
  92.   del:           writeln('DELETE key pressed.');
  93.   cntlhome:      writeln('CONTROL-HOME key pressed.');
  94.   cntlend:       writeln('CONTROL-END key pressed.');
  95.   cntlpgup:      writeln('CONTROL-PAGE UP key pressed.');
  96.   cntlpgdn:      writeln('CONTROL-PAGE DOWN key pressed.');
  97.   cntlleftarrow: writeln('CONTROL-LEFT ARROW key pressed.');
  98.   cntlrightarrow:writeln('CONTROL-RIGHT ARROW key pressed.');
  99.   else           writeln('Key pressed was not a keypad key!');
  100.  end;
  101.  setnumlock(numstate);
  102.  write('Key tests done.  Press RETURN.');
  103.  readstr(s,0,[]);
  104. end.